#include "obstaCles.h"

USING_NS_CC;

obstaCles::obstaCles(void)
{
}


obstaCles::~obstaCles(void)
{
}

bool obstaCles::init()
{
	if (!Sprite::init())
	{
		return false;
	}
	srand(time(NULL));

	int obstaCles_width=rand()%20+5;
	int obstaCles_heigh=rand()%30+10;
	Size size=Size(obstaCles_width,obstaCles_heigh);


	this->setPhysicsBody(PhysicsBody::createBox(size));
	this->setTextureRect(Rect(0,0,size.width,size.height));
	this->setColor(Color3B(0,0,0));
	this->setContentSize(size);
	this->setPositionX(Director::getInstance()->getVisibleSize().width);

	this->scheduleUpdate();

	this->getPhysicsBody()->setDynamic(false);
	this->getPhysicsBody()->setContactTestBitmask(1);
	return true;
}

void obstaCles::update(float dt)
{
	this->setPositionX(this->getPositionX()-2.5);
	if (this->getPositionX()<=0)
	{
		this->unscheduleUpdate();
		this->removeFromParent();
	}
}
